from selenium import webdriver
import time
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
class Grap:
    def __init__(self):
        # 设置驱动的路径,这是 selenium4之后的新写法
        self.service = Service(executable_path=r"C:\Program Files\Google\Chrome\Application\chromedriver.exe")
        # 实例化浏览器对象
        self.driver = webdriver.Chrome(service=self.service)

    # ----- # 等待 -----
    def impWait(self):
        self.driver.get('http://www.itcast.cn/')
        # 隐式等待,设置等待时间为10s
        self.driver.implicitly_wait(10)
        # 聊天框是一个frame，需要切换到frame
        self.driver.switch_to.frame('chatIframe')
        element = self.driver.find_element(By.CLASS_NAME,'service')
        print(element.text)

    def obsWait(self):
        self.driver.get('http://www.itcast.cn/')
        self.driver.switch_to.frame('chatIframe')
        element = WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element(By.CLASS_NAME,'service'))
        print(element.text)
    
if __name__ == '__main__':
    g = Grap()
    g.obsWait()


